package com.example.springboot.controller;

import com.example.springboot.service.ExcelOperateService;
import com.sun.javafx.util.Logging;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.logging.Logger;

/**
 * 对excel表格进行操作的Controller
 */
@RestController()
@RequestMapping("/query")
public class ExcelController {
    private static final Logger logger = Logger.getLogger(ExcelController.class.getName());
    @Autowired
    private ExcelOperateService excelOperateService;
    /**
     * 读取excel表格里面的数据
     */
    @PostMapping("/read")
    public void readExcel(String path){
        logger.info("读取"+path+"excel表格里面的数据====>开始");
        try {
            excelOperateService.readExcel(path);
        } catch (IOException e) {
            logger.info("读取"+path+"excel表格里面的数据{================>}异常");
            throw new RuntimeException(e);
        }
        logger.info("读取"+path+"excel表格里面的数据====>开始");
    }
    @PostMapping("/write")
    public void writeExcel(String path){
        logger.info("写入"+path+"excel表格里面的数据====>开始");
        try {
            excelOperateService.writeExcel(path);
        } catch (IOException e) {
            logger.info("写入"+path+"excel表格里面的数据{================>}异常");
            throw new RuntimeException(e);
        }
        logger.info("写入"+path+"excel表格里面的数据====>开始");
    }
}
